package com.le.tester.book.flightjava8.parameterpassing;


import java.util.ArrayList;
import java.util.List;

/**
 * createTime：2025-06-19 14:19
 * description：所有的参数都可以抽象化，看要不要那么做
 */
public interface Predicate<T> {
    boolean test(T t);


    static <T> List<T> filter(List<T> list, Predicate<T> predicate) {
//        new Comparator<Apple>(){
//
//            @Override
//            public int compare(Apple o1, Apple o2) {
//               return o1.getWeight().compareTo(o2.getWeight());
//            }
//        };
        ArrayList<T> result = new ArrayList<>();
        for (T t : list) {
            if (predicate.test(t)) {
                result.add(t);
            }
        }
        return result;
    }
}
